package com.zz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zz.entity.Sections;
import com.zz.service.SectionsService;

@RestController
public class SectionsController {
	@Autowired
	SectionsService sectionsService;
	
	@RequestMapping("/X-admin/findSection")
	public List<Sections> findSection(){
		List<Sections> slist=sectionsService.findAll();
		return slist;
	}
	@RequestMapping("/X-admin/findAllSection")
	public Object findAllSection(Integer page,Integer limit) {
		
		int count = sectionsService.count();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("data", sectionsService.findAll());
		map.put("count", count);
		return map;
	}
	//添加
	@RequestMapping("/X-admin/addSection")
	public Object addSection(Sections s) {
		try {
			sectionsService.save(s);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}
	
	
	//添加
	@RequestMapping("/X-admin/upSection")
	public Object upSection(Sections s) {
		try {
			sectionsService.save(s);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}
	
	//删除
	@RequestMapping("/X-admin/delSection")
	public Integer delSection(Integer id) {
		try {
			sectionsService.delete(id);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}

}
